home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11866 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.tamu.edu!tam2000!jrm4227
  2. From: jrm4227@tam2000.tamu.edu (Justin Ray Mcelhanon)
  3. Newsgroups: comp.lang.c,comp.unix.programmer,comp.unix.questions
  4. Subject: Correct usage of system call?
  5. Date: 27 Mar 1996 09:00:47 GMT
  6. Organization: Texas A&M University, College Station, TX
  7. Message-ID: <4jb03v$oi6@news.tamu.edu>
  8. NNTP-Posting-Host: tam2000.tamu.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.     Alright here is the situation I need help with, can not figure out the 
  12. problem after at least three hours of trying to fix it.  I have written a small
  13. c code that is a menu that calls up unix commands using sytems: 
  14.  
  15. i.e)
  16.    printf ("1. Pine");
  17.    printf ("2. Usenet (tin)\n");
  18.    printf ("3. Ftp\n");
  19.  
  20.    scanf("%d", &choice);
  21.     
  22.   switch (choice)
  23.      {
  24.     case 1:
  25.          printf ("Executing Pine\n");
  26.          system("pine");
  27.       break;     
  28.  
  29.  
  30. It works great, however, I'd like to add in a command to allow one to 
  31. type in the site name.  Example, when you call up the ftp case it does 
  32. a scanf(%s,site); (with site declared as an char string) anyway I then 
  33. want to take that and put it in the system command. ie system("ftp site"), 
  34. but that is not the proper syntax, how could I accomplish this? That will
  35. not work, I tested to see if the system command would even accept variables
  36. as input, so I tried system(&site); ( BTW system(site) kept giving segmentation
  37. faults) this code would properly send the output to unix shell, however, if
  38. a space is place in the string it only reads the first part, and it also 
  39. doesn't include ftp on the front.  What is the proper syntax to mix C
  40. variables and unix system calls?  Mind you I've taught the little C and unix
  41. I know from these news groups and such, so if something appears totally
  42. wrong, it might be :)  If you'd like a better explination of the problem,
  43. or want more of the code, email me at thorin@tamu.edu, and if you reply, 
  44. please Carbon Copy me a response via mail because I don't trust the usenet
  45. server, it plays Ollie North and cannot recall that post or reply.  Okay
  46. thanks for the help
  47.     
  48.     
  49. --
  50. ****************************************** A! JW2 WAR+++ PI++ BR+++ SL+++ SK+
  51. Yakko: "Well it's been fun friend,         R&R++ GDF++ GP+++++ B&M++ HIP- SN+
  52. but we've got to get back to               HN+++! MS+ ME+ CB~ MM++! KK-- CO++ 
  53. planet reality now" (Baloney and Friends)  GLF-- P++ $++ E26 Ee10 TSlappy A18
  54. Justin McElhanon----------thorin@tamu.edu   
  55. ******************************************
  56.